import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:mybase/base/tool/arouter/FFGoto.dart';
import 'package:mybase/base/tool/color/FFColor.dart';
import 'package:mybase/base/tool/extension/FFNumExt.dart';
import 'package:mybase/base/tool/package/FFPackage.dart';
import 'package:mybase/base/widget/layout/FFLineContainer.dart';
import 'package:mybase/base/widget/layout/FFTextButton.dart';
import 'package:myuis/language/LanguageValue.dart';
import 'package:myuis/manager/MyuisManager.dart';
import 'package:myuis/page/cancelSub/CancelSubPage.dart';

/**
 * @title 介绍如何收费的
 */
class SubExplainView extends StatefulWidget {
  // 背景颜色
  Color? bgColor;

  // 标题颜色
  Color? titleColor;

  // 小组标题颜色
  Color? itemTitleColor;

  // 小组正文颜色
  Color? itemTextColor;

  SubExplainView({
    super.key,
    this.bgColor,
    this.titleColor,
    this.itemTitleColor,
    this.itemTextColor,
  });

  @override
  State<SubExplainView> createState() => _SubExplainViewState();
}

class _SubExplainViewState extends State<SubExplainView> {
  bool showHowCancel = true;
  String appName = "";

  @override
  void initState() {
    super.initState();

    FFPackage.getPackage().then((info) {
      appName = info.appName;
      setState(() {});
    });
  }

  @override
  Widget build(BuildContext context) {
    widget.bgColor ??= rgba(71, 226, 113, 0.08);
    widget.titleColor ??= Colors.pink;
    widget.itemTitleColor ??= Colors.white;
    widget.itemTextColor ??= Colors.grey;

    return FFLineContainer(
      direction: Axis.vertical,
      margin: EdgeInsets.only(left: 16.w, right: 16.w),
      padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 20.w),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(16.w),
        color: widget.bgColor,
      ),
      children: [
        FFTextButton(
          text: LanguageValue.freetrialworks(getContext()),
          fontSize: 17.sp,
          fontColor: widget.titleColor,
          alignment: Alignment.center,
          textAlign: TextAlign.center,
          maxLines: 10,
          fontWeight: FontWeight.w700,
        ),

        // 今天，第三天，第四天
        ...[
          {
            "title": LanguageValue.today(getContext()),
            "text": LanguageValue.trial1(getContext()),
          },
          {
            "title": LanguageValue.today3(getContext()),
            "text": LanguageValue.trial3(getContext()),
          },
          {
            "title": LanguageValue.today4(getContext()),
            "text": LanguageValue.trial4(getContext()),
          },
        ]
            .map((e) => FFLineContainer(
                  direction: Axis.vertical,
                  children: [
                    //标题
                    FFLineContainer(
                      direction: Axis.horizontal,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      margin: EdgeInsets.only(top: 12.w),
                      children: [
                        Container(
                          width: 10.w,
                          height: 10.w,
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(100.w),
                            color: widget.itemTitleColor,
                          ),
                        ),
                        6.w.widthSpace,
                        FFTextButton(
                          text: e["title"],
                          fontSize: 15.sp,
                          fontColor: widget.itemTitleColor,
                          maxLines: 2,
                          fontWeight: FontWeight.w500,
                        ),
                      ],
                    ),

                    12.w.heightSpace,
                    // 正文
                    FFTextButton(
                      margin: EdgeInsets.only(left: 16.w),
                      text: e["text"],
                      fontSize: 14.sp,
                      fontColor: widget.itemTextColor,
                      fontLineHeight: 1.2,
                      maxLines: 100,
                    ),
                  ],
                ))
            .toList(),

        // 如何取消
        FFTextButton(
          notes: "触发后，该按扭消失",
          hiddenClearFrame: !showHowCancel,
          text: LanguageValue.howTowCancel(getContext()),
          fontSize: 15.sp,
          fontColor: widget.itemTextColor,
          maxLines: 4,
          textDecoration: TextDecoration.underline,
          textDecorationColor: widget.itemTextColor,
          margin: EdgeInsets.only(left: 16.w),
          padding: EdgeInsets.symmetric(vertical: 16.w),
          unconstrainedBox: true,
          onClick: () {
            // showHowCancel = false;
            // setState(() {});

            FFGoto.gotoPage(context, CancelSubPage());
          },
        ),

        //
        FFTextButton(
          notes: "如何取消按扭 触发后，该文本出现",
          hiddenClearFrame: showHowCancel,
          text: LanguageValue.HowCancelInfo(getContext(), appName),
          fontSize: 15.sp,
          fontColor: widget.itemTextColor,
          maxLines: 20,
          fontLineHeight: 1.2,
          margin: EdgeInsets.only(left: 16.w),
          padding: EdgeInsets.symmetric(vertical: 16.w),
        ),
      ],
    );
  }
}
